package 哈希表;

import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/9/23 20:22
 */
public class 动脑题360笔试 {

    /*
     题目描述：
     给一个 钥匙数组 nums[], nums[i] 表示 开 第 nums[i]的钥匙,  开门的时候,要注意, 必须 n - 1 开门之后, 才能 开 第 n  扇门
     请返回一个数组 , ans[] , ans[i] 表示第 i 扇门 是在第几天开的!
     */


    public void solve1() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int nums[] = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        int cur = 1, day = 0;
        TreeMap<Integer, Integer> map = new TreeMap<>();
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            if (cur == nums[i]) {
                cur++;
                System.out.print(i + 1 + " ");
            } else {
                queue.add(nums[i]);
            }
            while (!queue.isEmpty() && cur == queue.peek()) {
                queue.poll();
                cur++;
                System.out.print(i + 1 + " ");
            }
        }
    }

    static int var = 10;
    static Object LOCK = new Object();

    public static void main(String[] args) throws InterruptedException {
//        var++;
        Thread t1 = new Thread(() -> {
//            synchronized (LOCK){
//                var++;
//                try {
//                    TimeUnit.SECONDS.sleep(10);
//                    System.out.println("t1 ---> " + var);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
            var++;
            try {
                TimeUnit.SECONDS.sleep(10);
                System.out.println(var);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }, "t1");
        t1.start();

        TimeUnit.SECONDS.sleep(1);

        Thread t2 = new Thread(() -> {
            var++;
            System.out.println("t2 ----> " + var);
        }, "t2");
        t2.start();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);


        System.out.println("main over");

    }
}
